export default class ModelType {
  constructor(basicCesium) {
    this.basicCesium = basicCesium
    this.viewer = basicCesium.viewer;

    this.primitives = basicCesium.viewer.scene.primitives;
    this.entities = basicCesium.viewer.entities;
  }

  initEntity() {
    this.viewer.entities.removeAll()
    for (let lon = -180.0; lon < 180.0; lon += 10.0) {
      for (let lat = -85.0; lat < 85.0; lat += 10.0) {
         this.entities.add({
          rectangle: new Cesium.RectangleGraphics({
            coordinates: Cesium.Rectangle.fromDegrees(lon, lat, lon + 10.0, lat + 10.0),
            material: new Cesium.ColorMaterialProperty(Cesium.Color.fromRandom({
              alpha: 0.5
            })),
            outline: true,
            outlineColor: Cesium.Color.WHITE,
            outlineWidth: 1.5
          })

        })
      }
    }
  }

  initPrimitive() {
    this.primitives.removeAll();
    let instances = [];
    //循环创建随机颜色的矩形
    for (let lon = -180.0; lon < 180.0; lon += 10.0) {
      for (let lat = -85.0; lat < 85.0; lat += 10.0) {
        instances.push(new Cesium.GeometryInstance({
          geometry: new Cesium.RectangleGeometry({
            rectangle: Cesium.Rectangle.fromDegrees(lon, lat, lon + 10.0, lat + 10.0),
            vertexFormat: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
          }),
          attributes: {
            color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromRandom({
              alpha: 0.5
            }))
          }
        }));
      }
    }
    this.primitives.add(new Cesium.Primitive({
      geometryInstances: instances,
      appearance: new Cesium.PerInstanceColorAppearance(), //使用PerInstanceColorAppearance不同颜色来遮蔽每个实例
    }));
  }

  clearAll() {
    this.viewer.entities.removeAll()
    this.primitives.removeAll();
  }
}